package worker

import (
	"fmt"
	"time"
)

type WorkTask struct {
	Id int
}

func NewWorkTask(id int) *WorkTask {
	return &WorkTask{Id: id}
}

func CreateTask(taskNum int) chan *WorkTask {
	var taskChan = make(chan *WorkTask)
	go func() {
		for i := 0; i < taskNum; i++ {
			time.Sleep(time.Second)
			taskChan <- NewWorkTask(i)
			fmt.Printf("任务 [%d] 已创建完毕\n", i)
		}
		//发送一个特殊的任务标记所有任务已经执行完成
		taskChan <- NewWorkTask(-1)
	}()
	return taskChan
}
